home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Auge 4000 / Auge 4000 #21 (1988-05-25)(Amiga User Gruppe Einzugsgebiet 4000).zip / Auge 4000 #21 (1988-05-25)(Amiga User Gruppe Einzugsgebiet 4000).adf / Mastermind / Mastermind (.txt) < prev    next >
AmigaBASIC Source Code  |  1988-01-20  |  10KB  |  462 lines

  1. ' Mastermind V1.0  860804
  2. '
  3. ' The good ol' game of Mastermind...
  4. ' It's the machine playing the scorekeeper and the ever-lasting oponent
  5. ' who does all of the puzzle choosing.  Choose between Mastermind and
  6. ' SUPER Mastermind (heh heh heh)
  7. '
  8. ' Programmed By Ken Robertson of Montreal, Quebec
  9. ' August 1st, 1986
  10. '
  11. ' This program is FREEWARE and may be distributed without cost to anyone.
  12. ' However, if you like the game and would like to see more coming, feel
  13. ' free to send me a donation (I gotta eat, too) at
  14. '
  15. '     4130 Decarie, #11
  16. '     Montreal, Quebec,
  17. '     Canada
  18. '     H3A 2K1
  19. '
  20. ' I didn't put these comments in to print at the beginning as I feel
  21. ' that they're a little tacky to see, everytime the program comes up.
  22. '
  23. ' Any programs that begin with 'KenR Software Presents' was most probably
  24. ' written by me.  Expect good stuff.
  25. '
  26. DIM guess(5),rack(20,5),answer(5),unguess(5)
  27.  
  28. ' paint function key boxes for colours, cancel, and erase.
  29. RANDOMIZE TIMER
  30. SCREEN CLOSE 2
  31. SCREEN 2,640,200,4,2
  32. WINDOW 2,"Mastermind",,15,2
  33. PALETTE 0,0,0,0:PALETTE 1,0.7,0.7,0.7:PALETTE 8,0,0.5,0:PALETTE 10,1,1,0.13
  34. GOSUB drawcredits
  35. thesame=0
  36. FOR i=0 TO 9
  37. LINE (i*60-30*(i>4),174)-(i*60-30*(i>4)+40,186),i+3,bf
  38. NEXT i
  39. LINE (8*60+30,174)-(8*60+70,186),0,bf
  40.  
  41. LOCATE 23,73
  42. PRINT " Go ";
  43. topscore=99
  44.  
  45. LOCATE 1,1:PRINT "For instructions, press the 'Help' key now."
  46. firstime=1
  47. thesame=0
  48. startgame:
  49.  
  50. ' Generate permutation . . .
  51. answer(0)=0
  52. FOR i=1 TO 5
  53. test1:
  54.   g=INT(RND(1)*8)+1
  55.   IF thesame=0 THEN
  56.      testf=0
  57.      FOR j=0 TO i-1
  58.        IF g=answer(j) THEN testf=1
  59.      NEXT j
  60.      IF testf=1 THEN test1
  61.   END IF
  62.   answer(i)=g
  63. NEXT i
  64.  
  65. ' No two balls alike...
  66. guessnbr = 1
  67. ' draw rack
  68. FOR i=14 TO 550 STEP 29
  69.    LINE (i,14)-(i+29,77),1,b
  70. NEXT i
  71. notdone = -1
  72.  
  73. WHILE notdone
  74.  guessing = -1   
  75.  lastx=guessnbr*29
  76.  lasty=22
  77.  inpnbr = 1
  78.  WHILE guessing
  79.    CIRCLE (lastx,lasty),12,1
  80.    nochar=-1
  81.    WHILE nochar
  82.       a$=INKEY$
  83.       IF LEN(a$)<>0 THEN
  84.          a=ASC(a$)
  85.          IF a>128 AND a<140 THEN nochar=0
  86.          IF a=28 OR a=29 THEN nochar = 0
  87.          IF a=139 AND firstime=1 THEN GOSUB help
  88.       END IF
  89.    WEND
  90.    IF a<>139 AND a<>137 THEN firstime=0
  91.    IF a=139 AND firstime=0 THEN GOSUB hint
  92.    IF a=137 AND firstime THEN
  93.       thesame=1
  94.       COLOR 3
  95.       LOCATE 1,1
  96.       firstime=0
  97.       PRINT  "A more difficult game has just been chosen.  Pegs may now be the same color.";
  98.       GOTO startgame
  99.    END IF   
  100.    SOUND 220,0.31,127,0
  101.    SOUND 245,0.31,127,1
  102.  ' clear the first line of any message
  103.    LINE (0,0)-(639,9),0,bf  
  104.  '
  105.  '  A function key was pressed or an arrow key - is it a guess?
  106.  '  
  107.    IF a<137 AND a>128 THEN
  108.       ' Yep - add it to the list
  109.       rack (guessnbr,inpnbr)=a-128
  110.       'draw the circle
  111.       CIRCLE (lastx,lasty),11,a-126
  112.       PAINT (lastx,lasty),a-126
  113.       inpnbr=inpnbr + 1
  114.    END IF
  115.    
  116.    CIRCLE (lastx,lasty),12,0
  117.    IF a=28 THEN inpnbr=inpnbr-1
  118.    IF inpnbr=0 THEN inpnbr=1
  119.    IF a=29 THEN inpnbr=inpnbr+1
  120.    IF inpnbr = 6 THEN inpnbr = 1
  121.    lastx=guessnbr*29:lasty=inpnbr*12+10
  122.    CIRCLE (lastx,lasty),12,1
  123.  
  124.         
  125.    IF a=138 THEN
  126.       n=1
  127.       FOR i=1 TO 5
  128.          n=n*rack(guessnbr,i)
  129.       NEXT i
  130.       IF n<>0 THEN   
  131.          guessing=0
  132.       ELSE
  133.          LOCATE 1,1
  134.          COLOR 3
  135.          PRINT  "You must finish guessing before you 'Go'.";
  136.          SOUND 200,3,127,0
  137.          SOUND 210,3,127,1
  138.          SOUND 150,3,127,0
  139.          SOUND 160,3,127,1
  140.       END IF
  141.    END IF
  142.               
  143.  WEND  
  144.  'An input has been entered!  Check it against the answer
  145.  CIRCLE (lastx,lasty),12,0
  146.  FOR i=1 TO 5:guess(i)=answer(i):unguess(i)=rack(guessnbr,i):NEXT i
  147.  white=0:black=0
  148.  FOR i=1 TO 5
  149.    FOR j=1 TO 5
  150.       IF unguess(i)=guess(j) AND i=j THEN black=black+1:guess(j)=0:unguess(i)=99     
  151.    NEXT j
  152.  NEXT i
  153.  
  154.  FOR i=1 TO 5  
  155.    FOR j=1 TO 5
  156.      IF unguess(i)=guess(j) THEN white=white+1:guess(j)=0:unguess(i)=99
  157.    NEXT j
  158.  NEXT i
  159.  
  160.  ' ok - blacks and whites are summed up
  161.  IF black>0 THEN
  162.     FOR i=1 TO black
  163.       CIRCLE (guessnbr*29,75+6*i),5,1
  164.       SOUND 800,0.1,127,0
  165.       SOUND 810,0.1,127,0
  166.     NEXT i
  167.  END IF
  168.  
  169.  IF white > 0 THEN
  170.     FOR i=1 TO white
  171.        CIRCLE (guessnbr*29,75+6*black+6*i),5,7
  172.        PAINT (guessnbr*29,75+6*black+6*i),7
  173.        SOUND 500,0.1,127,0
  174.        SOUND 510,0.1,127,1
  175.     NEXT i
  176.  END IF
  177.  
  178.  LINE (14+(guessnbr-1)*29,77)-(guessnbr*29+14,110),1,b          
  179.  
  180.  guessnbr = guessnbr + 1
  181.  
  182.  IF black=5 THEN notdone = 0
  183.  IF guessnbr=20 THEN notdone=0
  184.  
  185. WEND
  186.  
  187. LOCATE 1,1
  188. IF guessnbr=20 AND black=5 THEN
  189.    FOR i=500 TO 100 STEP -10
  190.       SOUND i,0.1,100,0
  191.       SOUND i,0.1,100,1
  192.    NEXT i
  193.    PRINT "Wow.  You just got lucky, I guess.";
  194. END IF
  195.  
  196. IF guessnbr=20 AND black<5 THEN
  197.    SOUND 200,10,100,0
  198.    SOUND 300,10,100,1
  199.  
  200.    PRINT "Sorry, you've run out of turns.  The puzzle was:";
  201.    lastx=guessnbr*29
  202.    FOR i=1 TO 5
  203.       lasty=i*12+10
  204.       CIRCLE (lastx,lasty),11,answer(i)+2
  205.       PAINT (lastx,lasty),answer(i)+2
  206.    NEXT i   
  207.  
  208. END IF
  209.  
  210. IF guessnbr<20 AND guessnbr < topscore THEN
  211.    SOUND 200,5,100,0
  212.    SOUND 500,5,100,0
  213.    SOUND 200,5,100,1
  214.    SOUND 500,5,100,1
  215.  
  216.    PRINT "You've got it!  And beat the topscore!";
  217. END IF
  218.    
  219. IF guessnbr<20 AND guessnbr > topscore THEN
  220.    SOUND 200,5,100,0
  221.    SOUND 500,5,100,0
  222.    SOUND 300,5,100,0
  223.    SOUND 200,5,100,1
  224.    SOUND 500,5,100,1
  225.    SOUND 300,5,100,1
  226.    PRINT "Well, you've got it, but you've done better.";
  227. END IF
  228.  
  229. IF guessnbr < topscore THEN topscore=guessnbr-1
  230.  
  231. PRINT  "  Press any key to continue.";
  232. GOSUB keywait
  233.  
  234. LOCATE 20,1:COLOR 4:PRINT "Top Score:  ";topscore;
  235. total=total+guessnbr
  236. games=games+1
  237. IF games>1 THEN COLOR 3:PRINT "  Average:  ";total/games
  238.  
  239. LINE (0,0)-(619,110),0,bf
  240.  
  241.       
  242. GOTO startgame
  243.  
  244. drawcredits:
  245. ' Draw Opening Credits
  246. 'set border to black as well
  247.  
  248. LOCATE 12,29
  249. PALETTE 1,0,0,0:PALETTE 3,1,1,1:COLOR 3
  250. PRINT "KenR Software Presents";
  251. FOR i=1 TO 1500:x=0.1:NEXT i
  252. FOR i=1 TO 0 STEP -0.02
  253.   PALETTE 3,i,i,i
  254.   SCROLL (0,0)-(639,220),0,-1
  255. NEXT i  
  256. CLS
  257. FOR i=3 TO 5
  258.    PALETTE i,0.01,0.01,0.01
  259. NEXT i
  260.  
  261. COLOR 3
  262. cl=3:cll=1
  263. notend = -1
  264. WHILE notend
  265.    READ x,y
  266.    IF x=0 AND y=0 THEN notend=0
  267.    newletter=1*notend
  268.    WHILE newletter
  269.       READ x1,y1
  270.       IF x1=0 AND y1=0 THEN
  271.          AREAFILL 
  272.          newletter=0
  273.       ELSE
  274.          AREA (x*15+40,y*10+10)
  275.          x=x1:y=y1
  276.       END IF
  277.    WEND
  278.    cl=cl+1:IF cl=6 THEN cl=3
  279.    COLOR cl
  280.          
  281. WEND
  282. y=0
  283. FOR z=0 TO 0.8 STEP 0.04
  284.    SOUND 130,1,z*100,0
  285.    SOUND 131,1,z*100,1
  286.    PALETTE 3,z,y,0
  287.    PALETTE 4,0,z,y
  288.    PALETTE 5,y,0,z
  289.    y=y+0.02
  290.    SOUND 130,1,z*100,0
  291.    SOUND 131,1,z*100,1
  292.    PALETTE 3,z,y,0
  293.    PALETTE 4,0,z,y
  294.    PALETTE 5,y,0,z
  295.  
  296. NEXT z
  297.  
  298. FOR j=1 TO 50
  299.    SOUND 130,1,80,0
  300.    SOUND 131,1,80,1
  301.    SOUND 130,0.1,0,0
  302.    SOUND 131,0.1,0,0
  303.    IF RND(1)>0.9 THEN
  304.       n1=RND(1):n2=RND(1):n3=RND(1)
  305.       PALETTE 0,n1,n2,n3
  306.       PALETTE 1,n1,n2,n3
  307.       SOUND 3900,0.3,127,2
  308.       SOUND 5000,0.3,127,3
  309.       PALETTE 0,0,0,0
  310.       PALETTE 1,0,0,0
  311.    END IF   
  312. NEXT j   
  313.  
  314.  
  315. FOR z=0.8 TO 0 STEP -0.02
  316.    SOUND 130,1,z*100,0
  317.    SOUND 131,1,z*100,1
  318.    SOUND 133,1,z*100,2
  319.    SOUND 134,1,z*100,3
  320.    PALETTE 3,z,0,0
  321.    PALETTE 4,0,z,0
  322.    PALETTE 5,0,0,z
  323. NEXT z
  324.  
  325. CLS
  326. PALETTE 3,0.8,0.6,0.53
  327. PALETTE 4,0.3,0.4,1
  328. PALETTE 5,1,0.13,0.93
  329. PALETTE 6,0.2,0.93,0.87
  330. PALETTE 1,0.7,0.7,0.7
  331.  
  332. SOUND 50,25,127,0
  333. SOUND 51,25,127,1
  334. SOUND 100,10,127,0
  335. SOUND 101,10,127,1
  336. FOR i=127 TO 0 STEP -20
  337.    SOUND 100,2,i,0
  338.    SOUND 101,2,i,1
  339. NEXT i
  340.  
  341.  
  342.  
  343. RETURN  
  344.   
  345.   
  346. DATA 30,11,30,5,33,7,32,10,30,11,0,0
  347. DATA 29,11,29,5,30,8,31,5,30,11,29.5,7,29,11,0,0
  348. DATA 28,11,27,8,28,5,29,8,28,11,0,0
  349. DATA 20,11,23,5,24,7,25,5,28,11,20,11,0,0
  350. DATA 18.5,11,18.5,5,22,6,20,8,22,11,19.5,8.5,18.5,11,0,0
  351. DATA 16,11,16,5,19,6,17,7,19,8,17,9,19,10,16,11,0,0
  352. DATA 14.5,11,14.5,6.5,13,5.5,15,5,17,5.5,15.5,6,15.5,11,14.5,11,0,0
  353. DATA 13,11,10,8,12,9,11,6,12,5,14,6,12,7,14,10,13,11,0,0
  354. DATA 8,11,10,5,12,11,8,11,0,0
  355. DATA 0,11,3,0,4,4,5,0,10,11,0,11,0,0
  356. DATA 0,0
  357.  
  358. help:
  359.  
  360. LOCATE 12,1
  361. COLOR 5
  362. PRINT "This is the game of Mastermind.  Originally by Parker Brothers, the";
  363. LOCATE 13,1
  364. PRINT "object of the game is to guess the 5 colors of the pegs in the";
  365. LOCATE 14,1
  366. PRINT "puzzle." ;
  367. LOCATE 15,1
  368. PRINT  "   These colors may be of any of the 8 boxes below, each of which";
  369. LOCATE 16,1
  370. PRINT "correspond to a function key on your keyboard.  (Novel idea, eh?)";
  371. LOCATE 17,1
  372. COLOR 1
  373. PRINT "Press any key to go on.";
  374. GOSUB keywait
  375.  
  376. ' clear area
  377. LINE (0,80)-(639,170),0,bf
  378. COLOR 6
  379. LOCATE 12,1
  380. PRINT "As you make each guess, the round cursor will automatically advance to";
  381. LOCATE 13,1
  382. PRINT "the next space.  You can use the up and down cursor keys to move the cursor";
  383. LOCATE 14,1
  384. PRINT  "as well.";
  385. COLOR 1
  386. LOCATE 15,1
  387. PRINT  "Press any key to go on.";
  388.  
  389. GOSUB keywait
  390. ' clear area
  391. LINE (0,80)-(639,170),0,bf
  392. LOCATE 12,1:COLOR 7
  393. PRINT  "   After you are satisfied that your guess is what you want, press F10";
  394. LOCATE 13,1
  395. PRINT  "(The box that has 'Go' in it) to register your guess.";
  396. LOCATE 14,1
  397. PRINT  "   The Amiga will tell you if   1) A 'peg' is in the right spot";
  398. LOCATE 15,1
  399. PRINT  "                           or   2) The color is correct, but the spot";
  400. LOCATE 16,1
  401. PRINT  "                                   is not.";
  402. LOCATE 17,1
  403. PRINT  "These are signified by a black circle and a white circle respectively.";
  404.           
  405. COLOR 1
  406. LOCATE 18,1
  407. PRINT  "Press any key to go on.";
  408.  
  409. GOSUB keywait
  410. ' clear area
  411. LINE (0,80)-(639,170),0,bf
  412. LOCATE 12,1:COLOR 8
  413. PRINT  " - All spots must be full in order to make a guess." ;
  414. LOCATE 13,1
  415. PRINT  " - The pegs will all be different colors, unless you want a harder";
  416. LOCATE 14,1
  417. PRINT  "   game - in which case, press F9 when you exit help (or when you start";
  418. LOCATE 15,1
  419. PRINT  "up the game next time.)";
  420. LOCATE 16,1
  421. COLOR 9
  422. PRINT  "By the way, you can only access help UNTIL you make a guess.  After that,";
  423. LOCATE 17,1
  424. PRINT  "I'd think you're asking for a hint.  I MAY give you one, but it'll cost.";
  425. COLOR 1
  426. LOCATE 18,1
  427. PRINT  "Press any key to go back.";
  428.  
  429. GOSUB keywait
  430. ' clear area
  431. LINE (0,80)-(639,170),0,bf
  432. LOCATE 12,1:COLOR 9
  433.  
  434. RETURN
  435.  
  436. keywait:
  437. ' first clear the buffer
  438. nochar=-1
  439. WHILE nochar
  440.    a$=INKEY$
  441.    IF LEN(a$)=0 THEN  nochar=0
  442. WEND
  443.  
  444. ' now wait for the next key
  445. nochar=-1
  446. WHILE nochar
  447.    a$=INKEY$
  448.    IF LEN(a$)<>0 THEN nochar=0
  449. WEND      
  450.  
  451. RETURN                                                 
  452.                                                  
  453. hint:
  454.  
  455. LOCATE 1,1
  456. COLOR 8
  457. PRINT  "Hints are not available in this version.";
  458. RETURN
  459.  
  460.  
  461.